import {
	useRequest
} from "./request.js";

import {
	useUserStore
} from "../stores/useUserStore.js";

export const useWishlistApis = () => {

	const userStore = useUserStore();
	const config = {
		header: {
			authorization: userStore.token
		}
	}
	const request = useRequest();


	// 想吃榜
	function getWishlist() {
		return request.get("/api/wishes/statistics/next-week", config);
	}

	// 我想吃
	function getMyWishlist() {
		const id = userStore.id;
		return request.get(`/api/users/${id}/wishes`, config);
	}

	// 添加一个下周想吃的菜品
	function addOneToWishlist(dishesId) {
		const id = userStore.id;
		return request.post(`/api/users/${id}/wishes`, {
			dishesId
		}, config);
	}

	// 删除一个下周想吃的菜品
	function deleteOneFromDishlist(dishesId) {
		const userId = userStore.id;
		return request.delete(`/api/users/${userId}/wishes/${dishesId}`, config);
	}

	// 创建、修改下周想吃菜品
	function updateMyWishlist(dishesIdList) {
		const id = userStore.id;
		return request.put(`/api/users/${id}/wishes`, {
			data: {
				dishesIdList
			},
			...config
		})
	}

	return {
		getWishlist,
		getMyWishlist,
		addOneToWishlist,
		deleteOneFromDishlist,
		updateMyWishlist,
	}
}